package com.jiangyg.mall.product.controller;

import com.jiangyg.mall.core.support.restful.Pagination;
import com.jiangyg.mall.core.support.restful.Result;
import com.jiangyg.mall.product.dto.CommentReplayDTO;
import com.jiangyg.mall.product.vo.CommentReplayVO;
import com.jiangyg.mall.product.service.CommentReplayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 类描述：商品评价回复关系控制器
 *
 * @author jiangyg
 * @version email@jiangyg.com
 * @date 2021-10-30 07:38:49
 */
@RestController
@RequestMapping("/product/commentReplay")
public class CommentReplayController {

    /**
     * 商品评价回复关系接口
     */
    private final CommentReplayService commentReplayService;

    @Autowired
    public CommentReplayController(CommentReplayService commentReplayService) {
        this.commentReplayService = commentReplayService;
    }

    /**
     * 功能描述：商品评价回复关系分页查询
     *
     * @param request    请求
     * @param pagination 分页参数
     * @return 返回分页商品评价回复关系
     */
    @ResponseBody
    @PostMapping("/select")
    public Result<Pagination<CommentReplayVO>> select(HttpServletRequest request, @RequestBody Pagination<CommentReplayVO> pagination) throws Exception {
        return Result.ok(commentReplayService.selectPagination(pagination));
    }

    /**
     * 功能描述：保存或者修改商品评价回复关系
     *
     * @param request 请求
     * @param dto     商品评价回复关系
     * @return 结果
     */
    @ResponseBody
    @PostMapping("/save")
    public Result<Object> save(HttpServletRequest request, @RequestBody @Validated CommentReplayDTO dto) throws Exception {
        return Result.saveOrUpdate(commentReplayService.saveOrUpdate(dto));
    }

    /**
     * 功能描述：根据ID获取商品评价回复关系
     *
     * @param request 请求
     * @param commentReplayId  商品评价回复关系ID
     * @return 结果
     */
    @ResponseBody
    @PostMapping("/info")
    public Result<CommentReplayVO> info(HttpServletRequest request, @RequestParam(name = "commentReplayId") Long commentReplayId) throws Exception {
        return Result.ok(commentReplayService.selectById(commentReplayId));
    }

    /**
     * 功能描述：删除商品评价回复关系
     *
     * @param request 请求
     * @param commentReplayIds 批量删除的商品评价回复关系ID
     * @return 结果
     */
    @ResponseBody
    @PostMapping("/delete")
    public Result<Object> delete(HttpServletRequest request, @RequestParam(name = "commentReplayIds") List<Long> commentReplayIds) {
        return Result.delete(commentReplayService.delete(commentReplayIds));
    }

}
